{% extends "base.html" %}

{% block content %}

<div id="menu-toolbar" class="ui-state-active">
    <ul class ="right">
    </ul>
    <ul class ="left">
        <li><a href="/iterations?project_id={{ project.key.id }}">{{ project.name }}</a></li>
    </ul>
</div>

<div id ="title-container">
    <h2>Iteration Form</h2>
</div>

<div class="form_container">
    <form action="/iteration_form?id={{iteration_id}}&project_id={{ project.key.id }}" method="post" id="iteration_form">
        <input type="hidden" name="project_id" value="{{ project.key.id }}">
        <input type="hidden" name="id" value="{{ iteration_id }}">
        <fieldset>
            <legend>Iteration details</legend>
            <ol>
                {{ form.as_ul }}
                <li class="center">
                    <input type="submit" value="Save">
                    <input type="submit" value="Cancel">
                </li>
            </ol>
        </fieldset>
    </form>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $( "#id_start_date, #id_end_date" ).datepicker({
            showOn: "button",
            buttonImage: "/static/css/images/calendar.gif",
            buttonImageOnly: true
        });
        $(function() {
            $( "input:submit").button();
        });

        $("form input[type=submit]").click(function() {
            $( 'input[type=submit][clicked=true]' ).removeAttr("clicked");
            $(this).attr("clicked", "true");
            $(this).parent().parent().parent().submit();
        });
        $("#iteration_form").submit(function(event) {
            var $form = $( this ),
            source = $form.find( 'input[type=submit][clicked=true]' ).val();
            if (source.toLowerCase() == 'cancel') {
                event.preventDefault();
                if ('{{ iteration_id }}' != '') {
                    window.location = "/?id_it=" + '{{ iteration_id }}';
                } else {
                    window.location = "/iterations?project_id=" + '{{ project.key.id }}';
                }
            }
        });
    });
</script>
{% endblock %}